********************************************************************************

*This do-file produces all the results in the main text and appendix for "Warfare, Fiscal Gridlock, and State Formation during Europe’s Military Revolution"

*April 9, 2024

********************************************************************************
********************************************************************************
********************************************************************************

*Preamble

*Set Stata options

clear all
set more off 
set memory 500m
set maxvar 32767
set matsize 5000

*Set directories

global maindirectory "D:\Dropbox\Suppression of Rep Govt\Replication"
global rawdata "$maindirectory\raw_data"
global cleandata "$maindirectory\clean_data"
global output "$maindirectory\output"
global dofiles "$maindirectory\do_files"

********************************************************************************
********************************************************************************
********************************************************************************

*Results in Main Text

********************************************************************************
********************************************************************************
********************************************************************************

cd "$output"
cap log close
log using "make_output.log", text replace

cd "$cleandata"

********************************************************************************
*Figure 1: Two Paths of Fiscal Development in Early Modern Europe
********************************************************************************

use "data_figure1", clear

twoway (connected share_status_quo year, lpattern(solid) mlcolor(black) msymbol(i)) ///
	(connected share_fisc_abs year, lpattern(longdash_dot) lcolor(red) msymbol(i)) ///
	(connected share_fisc_parl year, lpattern(shortdash) lcolor(blue) msymbol(i)) ///
	, scheme(lean1) ///
	title() ///
	xlabel(1500(50)1800) ///
	xtick(1500(50)1800) ///
	xmtick(1500(10)1800) ///
	xtitle("") ///
	ymtick(0(.2)1) ///
	ylabel(0(.2)1, format(%9.1f)) ///
	ytitle("Share of units") ///
	legend(col(3) pos(6) label(1 "Crown-and-parliament units") label(2 "Absolutist units") label(3 "Parliamentary units")  order(1 2 3) region(lcolor(black))) 
cd "$output"	
graph export figure1.png, as(png) width(2500) replace
cap graph close graph

clear

********************************************************************************
*Report the numbers of reforms in the paper's introduction
********************************************************************************

cd "$cleandata"
use "data_CDOFG_main", clear

cd "$output"

tab tax_reform
tab exp_reform
tab parl_move
tab irb_move

********************************************************************************
*Table 1: External War and Tax Reform in Early Modern Europe
********************************************************************************

cap erase table1.txt
cap erase table1.xml

sort unitid year
xtset unitid year

*Column 1		
xtreg tax_reform extwarmajor_10 i.year if year<=tax_maxyear, fe vce(cluster unitid)
outreg2 extwarmajor_10 using table1, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, No, SE Cluster, Territory, Method, OLS)	

*Column 2
xtreg tax_reform extwarmajor_10 politytrend* i.year if year<=tax_maxyear, fe vce(cluster unitid)
outreg2 extwarmajor_10 using table1, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, Yes, SE Cluster, Territory, Method, OLS)	

*Column 3
xtreg tax_reform extwarmajor_10 casualtywarmajor_10 politytrend* i.year if year<=tax_maxyear, fe vce(cluster unitid)
outreg2 extwarmajor_10 casualtywarmajor_10 using table1, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, Yes, SE Cluster, Territory, Method, OLS)	

*Column 4	
xtreg tax_reform extwarmajor_10 casualtywarmajor_10 extwarloss_10 politytrend* i.year if year<=tax_maxyear, fe vce(cluster unitid)
outreg2 extwarmajor_10 casualtywarmajor_10 extwarloss_10 using table1, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, Yes, SE Cluster, Territory, Method, OLS)	

*Column 5
xtreg tax_reform extwarmajor_10 casualtywarmajor_10 extwarloss_10 L.urbrate politytrend* i.year if year<=tax_maxyear, fe vce(cluster unitid)
outreg2 extwarmajor_10 casualtywarmajor_10 extwarloss_10 L.urbrate using table1, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, Yes, SE Cluster, Territory, Method, OLS)	

*Column 6
xtreg tax_reform extwarmajor_10 casualtywarmajor_10 extwarloss_10 L.ln_gdppc politytrend* i.year if year<=tax_maxyear, fe vce(cluster unitid)
outreg2 extwarmajor_10 casualtywarmajor_10 extwarloss_10 L.ln_gdppc using table1, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, Yes, SE Cluster, Territory, Method, OLS)	

********************************************************************************
********************************************************************************
********************************************************************************

*Results in Appendix

********************************************************************************
********************************************************************************
********************************************************************************

********************************************************************************
*Table A.1: Alternative War Participation Variables           
********************************************************************************

cap erase tableA1.txt
cap erase tableA1.xml

*Column 1	
xtreg tax_reform extwarmajor_5 politytrend* i.year if year<=tax_maxyear, fe vce(cluster unitid)
outreg2 extwarmajor_5 using tableA1, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, Yes, SE Cluster, Territory, Method, OLS)

*Column 2	
xtreg tax_reform L.extwarmajor politytrend* i.year if year<=tax_maxyear, fe vce(cluster unitid)
outreg2 L.extwarmajor using tableA1, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, Yes, SE Cluster, Territory, Method, OLS)

*Column 3	
xtreg tax_reform n_extwarmajor_10 politytrend* i.year if year<=tax_maxyear, fe vce(cluster unitid)
outreg2 n_extwarmajor_10 using tableA1, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, Yes, SE Cluster, Territory, Method, OLS)	
	
********************************************************************************
*Table A.2: Composite Monarchy ("Polity") Fixed Effects           
********************************************************************************

cap erase tableA2.txt
cap erase tableA2.xml

*Column 1	
xi: reg tax_reform extwarmajor_10 i.polityid i.year if year<=tax_maxyear, vce(cluster polityid)
outreg2 extwarmajor_10 using tableA2, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Polity FE, Yes, Territory FE, No, Polity Trends, No, SE Cluster, Monarchy, Method, OLS)

*Column 2		
xi: reg tax_reform extwarmajor_10 politytrend* i.polityid i.year if year<=tax_maxyear, vce(cluster polityid)
outreg2 extwarmajor_10 using tableA2, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel  append ///
	addtext(Year FE, Yes, Polity FE, Yes, Territory FE, No, Polity Trends, Yes, SE Cluster, Monarchy, Method, OLS)
	
********************************************************************************
*Table A.3: Cluster Standard Errors at Composite Monarchy ("Polity") Level
********************************************************************************

cap erase tableA3.txt
cap erase tableA3.xml

*Column 1	
xtreg tax_reform extwarmajor_10 i.year if year<=tax_maxyear, fe vce(cluster polityid)
outreg2 extwarmajor_10 using tableA3, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, No, SE Cluster, Monarchy, Method, OLS)	

*Column 2	
xtreg tax_reform extwarmajor_10 politytrend* i.year if year<=tax_maxyear, fe vce(cluster polityid)
outreg2 extwarmajor_10 using tableA3, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, Yes, SE Cluster, Monarchy, Method, OLS)		
	
********************************************************************************
*Table A.4: Conley Standard Errors
********************************************************************************

cd "$dofiles"

cap program drop ols_spatial_HAC
do ols_spatial_HAC.ado
do reg2hdfespatial-id1id2.ado
cap ssc install tmpdir
cap ssc install reg2hdfe

cd "$output"

cap erase tableA4.txt
cap erase tableA4.xml

sort unitid year
xtset unitid year

*Column 1
forvalues i=100(100)500 {

reg2hdfespatial tax_reform extwarmajor_10 politytrend* if year<=tax_maxyear, panelvar(unitid) timevar(year) lat(latitude_capital) lon(longitude_capital) ///
		distcutoff(`i') 
	outreg2 extwarmajor_10 using tableA4, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, Yes, SE, Conley, Method, OLS)	
	}

********************************************************************************
*Table A.5: Intensive Margin of Reform 
********************************************************************************

cd "$output"

preserve 

********************************************************************************

*France

drop if unit=="artois (FRA)" | unit=="basse-navarre" | unit=="béarn" | ///
	unit=="bigorre" | unit=="bourgogne" | unit=="bresse" | unit=="bretagne" | unit=="bugey" | ///
	unit=="cambrésis" | unit=="charolais" | unit=="corse" | unit=="flandre" | unit=="foix" | ///
	unit=="franche-comté (FRA)" | unit=="gévaudan" | unit=="hainaut" | unit=="labourd" | unit=="languedoc" | ///
	unit=="mâconnais" | unit=="marsan" | unit=="nébouzan" | unit=="provence" | unit=="quatre-vallées" | ///
	unit=="soule" | unit=="velay" | unit=="vivarais" 

********************************************************************************
	
*Hungary

drop if unit=="kingdom of hungary" 

********************************************************************************

*Spain

drop if unit=="principality of asturias" | unit=="kingdom of galicia" | ///
	unit=="lordship of biscay" | unit=="province of gipuzkoa" | unit=="province of alava" | ///
	unit=="kingdom of navarre" 

drop if unit=="duchy of brabant" | unit=="duchy of limburg" | ///
	unit=="artois (SPA)" | unit=="county of flanders" | unit=="county of namur" | ///
	unit=="couny of hainaut" | unit=="lordship of mechelen"

********************************************************************************

cap erase tableA5.txt
cap erase tableA5.xml

xtset unitid year

*Column 1	
xtreg tax_reform extwarmajor_10 i.year if year<=tax_maxyear, fe vce(cluster unitid)
outreg2 extwarmajor_10 using tableA5, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, No, SE Cluster, Territory, Method, OLS)	

*Column 2	
xtreg tax_reform extwarmajor_10 politytrend* i.year if year<=tax_maxyear, fe vce(cluster unitid)
outreg2 extwarmajor_10 using tableA5, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, Yes, SE Cluster, Territory, Method, OLS)	

restore

********************************************************************************
*Table A.6: Dynasty Fixed Effects and Ability of Individual Rulers 
********************************************************************************

cap erase tableA6.txt
cap erase tableA6.xml

xtset unitid year

*Column 1	
xi: reg tax_reform extwarmajor_10 politytrend* i.dynastyid i.year if year<=tax_maxyear, vce(cluster unitid)
outreg2 extwarmajor_10 using tableA6, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Dynasty FE, Yes, Territory FE, Yes, Polity Trends, Yes, Dynasty Trends, No, SE Cluster, Territory, Method, OLS)	
	
*Column 2	
xi: reg tax_reform extwarmajor_10 dynastytrend* i.dynastyid i.year if year<=tax_maxyear, vce(cluster unitid)
outreg2 extwarmajor_10 using tableA6, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Dynasty FE, Yes, Territory FE, Yes, Polity Trends, No, Dynasty Trends, Yes, SE Cluster, Territory, Method, OLS)		

*Column 3	
xtreg tax_reform extwarmajor_10 ability politytrend* i.year if year<=tax_maxyear, fe vce(cluster unitid)
outreg2 extwarmajor_10 ability using tableA6, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Dynasty FE, No, Territory FE, Yes, Polity Trends, Yes, Dynasty Trends, No, SE Cluster, Territory, Method, OLS)	

*Column 4	
xi: reg tax_reform extwarmajor_10 ability politytrend* i.dynastyid i.year if year<=tax_maxyear, vce(cluster unitid)
outreg2 extwarmajor_10 ability using tableA6, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Dynasty FE, Yes, Territory FE, Yes, Polity Trends, Yes, Dynasty Trends, No, SE Cluster, Territory, Method, OLS)	

*Column 5	
xi: reg tax_reform extwarmajor_10 ability dynastytrend* i.dynastyid i.year if year<=tax_maxyear, vce(cluster unitid)
outreg2 extwarmajor_10 ability using tableA6, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Dynasty FE, Yes, Territory FE, Yes, Polity Trends, No, Dynasty Trends, Yes, SE Cluster, Territory, Method, OLS)	

********************************************************************************
*Table A.7: Additional Controls
********************************************************************************

cap erase tableA7.txt
cap erase tableA7.xml

*Column 1
xtreg tax_reform extwarmajor_10 dist_witt_1500-dist_witt_1800 politytrend* i.year if year<=tax_maxyear, fe vce(cluster unitid) 
outreg2 extwarmajor_10 using tableA7, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, Yes, SE Cluster, Territory, Method, OLS)	
	
*Column 2
xtreg tax_reform extwarmajor_10 dist_mainz_1500-dist_mainz_1800 politytrend* i.year if year<=tax_maxyear, fe vce(cluster unitid) 
outreg2 extwarmajor_10 using tableA7, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, Yes, SE Cluster, Territory, Method, OLS)	

********************************************************************************
*Table A.8: 10-Year Data Averages
********************************************************************************

preserve

********************************************************************************

*Generate decade of reforms

gen tax_reform_y10=0
replace tax_reform_y10=year if tax_reform==1
nsplit tax_reform_y10, digits(3,1) gen (cc_dd yy)
drop tax_reform_y10
gen tax_reform_y10=cc_dd*10
drop cc_dd yy

********************************************************************************

*Make decade indicator

gen year10=.
forvalues i = 1500(10)1800{
	replace year10=`i' if year>=`i' & year<=`i'+9
}

********************************************************************************

*Make outcome variables

egen tax_maxyear10=max(year10*(tax_reform==1)),by(unit)
	
********************************************************************************

*Collapse data

sort unitid year

collapse(mean) polityid tax_reform_y10 tax_maxyear10 extwarmajor_10, by(unitid year10)

replace tax_reform_y10=1 if tax_reform_y10!=0

********************************************************************************

*Make polity trends

tab polityid, gen(n_polityid)
	forvalues i = 1(1)9 {
		gen politytrend`i'=n_polityid`i'*year10
}

********************************************************************************

cap erase tableA8.txt
cap erase tableA8.xml

sort unitid year10
xtset unitid year10

*Column 1
xtreg tax_reform_y10 extwarmajor_10 i.year10 if year<=tax_maxyear10, fe vce(cluster unitid)
outreg2 extwarmajor_10 using tableA8, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Period FE, Yes, Territory FE, Yes, Polity Trends, No, SE Cluster, Territory, Method, OLS)	

*Column 2
xtreg tax_reform_y10 extwarmajor_10 i.year10 politytrend* if year<=tax_maxyear10, fe vce(cluster unitid)
outreg2 extwarmajor_10 urbrate using tableA8, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Period FE, Yes, Territory FE, Yes, Polity Trends, Yes, SE Cluster, Territory, Method, OLS)	

restore

********************************************************************************
*Table A.9: Exclude Participation in War of American Revolution
********************************************************************************

xtset unitid year

cap erase tableA9.txt
cap erase tableA9.xml

*Column 1	
xtreg tax_reform extwarmajorWAMR_10 i.year if year<=tax_maxyear, fe vce(cluster unitid)
outreg2 extwarmajorWAMR_10 using tableA9, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, No, SE Cluster, Territory, Method, OLS)	

* Column 2
xtreg tax_reform extwarmajorWAMR_10 politytrend* i.year if year<=tax_maxyear, fe vce(cluster unitid)
outreg2 extwarmajorWAMR_10 using tableA9, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, Yes, SE Cluster, Territory, Method, OLS)	

********************************************************************************
*Table A.10: Include Territorial Units Briefly Affiliated with Denmark, Prussia, or Sweden
********************************************************************************

clear
cd "$cleandata"
use "data_A10", clear

cd "$output"

cap erase tableA10.txt
cap erase tableA10.xml

sort unitid year
xtset unitid year

* Column 1		
xtreg tax_reform extwarmajor_10 i.year if year<=tax_maxyear, fe vce(cluster unitid)
outreg2 extwarmajor_10 using tableA10, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, No, SE Cluster, Territory, Method, OLS)	

* Column 2	
xtreg tax_reform extwarmajor_10 politytrend* i.year if year<=tax_maxyear, fe vce(cluster unitid)
outreg2 extwarmajor_10 using tableA10, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, Yes, SE Cluster, Territory, Method, OLS)	

********************************************************************************
*Table A.11: Internal War and Expenditure Reform in Early Modern Europe
********************************************************************************

clear
cd "$cleandata"
use "data_CDOFG_main", clear

cd "$output"
cap erase tableA11.txt
cap erase tableA11.xml

sort unitid year
xtset unitid year

*Column 1	
xtreg exp_reform intwarmajor_10 i.year if year<=max(tax_maxyear, exp_maxyear), fe vce(cluster unitid)
outreg2 intwarmajor_10 using tableA11, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, No, SE Cluster, Territory, Method, OLS)	

*Column 2
xtreg exp_reform intwarmajor_10 i.year politytrend* if year<=max(tax_maxyear, exp_maxyear), fe vce(cluster unitid)
outreg2 intwarmajor_10 using tableA11, st(coef se pval) paren(se) br(pval) bdec(3) nocon excel append ///
	addtext(Year FE, Yes, Territory FE, Yes, Polity Trends, Yes, SE Cluster, Territory, Method, OLS)	

clear
log close